package net.sipvip.client;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.ui.DecoratedPopupPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Image;

public class YTplayer extends Image {

	DecoratedPopupPanel popup = new DecoratedPopupPanel(true);
	final String videostr;
//	final String imagestr;

	public YTplayer(String videostrvar) {
		super();
		videostr = videostrvar;
//		imagestr = imagestrvar;
		sinkEvents(Event.ONCLICK);

	}

	public void onBrowserEvent(Event event) {
		switch (DOM.eventGetType(event)) {
		case Event.ONCLICK:
			GWT.log(this.getUrl(), null);
			String videoimagestr = jwplayerstr(videostr);

			HTML player = new HTML(videoimagestr);
			popup.setWidget(player);
			int left = this.getAbsoluteLeft() - 10;
			int top = this.getAbsoluteTop() + this.getHeight() + 20;
			popup.setPopupPosition(left, top);
			popup.show();

			break;

		// case Event.ONMOUSEOUT:
		// popup.removeFromParent();
		// break;

		default:
			break;
		}
	}

	String jwplayerstr(String videostr) {
		String playerstr = "<object width=\"425\" height=\"344\"><param name=\"movie\" value=\"http://www.youtube.com/v/" + videostr + "&hl=en&fs=1&\"></param><param name=\"allowFullScreen\" value=\"true\"></param><param name=\"allowscriptaccess\" value=\"always\"></param><embed src=\"http://www.youtube.com/v/" + videostr + "&hl=en&fs=1&\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" allowfullscreen=\"true\" width=\"425\" height=\"344\"></embed></object>";

		return playerstr;

	}

}
